<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
</head>

<body>
    <div id="app">
        <div v-if="toggle">
            <h2>{{title}}</h2>
            <h4 v-once>msg -- {{msg}}</h4>
            <h5>{{flag ? '今天肯定要下大雨':'今天应该没有雨'}}</h5>
            <p>
                <input type="text" v-model="msg">
            </p>
            <div v-text="word">
                word --
            </div>
            <div v-html="tag"></div>
            <p :data-index="idx" :data-msg="msg" @click="change(10)">hello--{{idx}}</p>
        </div>
        <button v-on:click="changeToggle">点击显示和隐藏</button>
        <div>
            <h3>txt -- {{txt}}</h3>
            <!-- 文本翻转 利用裁切 反转 拼接完成 -->
            <h4>reverseTxt -- {{txt.split("").reverse().join('')}}</h4>
            <!-- 第二种 -->
            <h5>mytxt == {{mytxt}}</h5>

        </div>
    </div>


    <div id="demo">
        <h1>{{ones}}</h1>
        <p>{{msg}}</p>
        <p>{{word}}</p>
    </div>
</body>
<script>

    // 非官方封装
    function MyVue(options) {
        // 构造函数
        this.options = options
        this.el = this.options.el
        this.data = this.options.data
        this.root = document.querySelector(this.el);
        this._init = function () {
            for (var key in this.data) {
                console.log(key);
                this[key] = this.data[key]
                var reg = new RegExp("{{" + '{0,}' + key + ' {0,}' + "}}", 'gi');
                this.root.innerHTML = this.root.innerHTML.replace(reg, this[key])
            }
        }
        this._init()/* 初始化 */
    }
    new MyVue({
        el: "#demo",
        data: {
            ones: "Vue + React",
            msg: "真的很烦",
            word: "I am so fidget",

        }
    })


    const vm = new Vue({
        data: {

            title: "模板语法 + 计算属性 ",
            msg: "Vue + React + 小程序 ",
            flag: !!1,
            word: "wh2105-天道酬勤",
            tag: "<u>原价:1000</u>",
            hello: "",
            idx: 2105,
            toggle: true,
            txt: "2105 yyds"

        },
        computed: {
            mytxt() {
                return this.txt.split('').reverse().join('-')
            }
        },
        methods: {
            changeToggle() {
                this.toggle = !this.toggle;
            },
            change(n) {
                this.idx += n;
            }
        },
        mounted() {
            document.getElementsByTagName("title")[0].innerHTML = this.title
            this.hello = "hello 2105";
        }
    }).$mount("#app")
</script>

</html>